%% Begin van huistaak2: vorm bepalen?
clear all
close all
clc


figure;
R = rand(5000,2);
R(:,1)=R(:,1)*5-2.5;
R(:,2)=R(:,2)*4-0.5;
inside = is_inside(R(:,1),R(:,2));
index = find(inside);
nindex = setdiff(1:length(inside),index);
plot(R(index,1),R(index,2),'ro',R(nindex,1),R(nindex,2),'bo');

%% Oppervlakte bepalen voor oplopende N
exact =  7.9175274853766402778;
h = waitbar(0,'Roel is cool');

iteraties = 100;
experimenten = 10;
points = floor(logspace(0,7,iteraties));
oppervlakte = zeros(iteraties,experimenten);
for j=1:10,
    figure;
    for i=1:iteraties,
        R = rand(points(i),2);
        R(:,1)=R(:,1)*5-2.5;
        R(:,2)=R(:,2)*4-0.5;
        inside = is_inside(R(:,1),R(:,2));
        oppervlakte(i,j) = length(find(inside))/points(i)*20;
    end
    waitbar(j/10,h);
    loglog(points,abs(oppervlakte(:,j)-exact)./exact)
end

%% plotting oppervlakte
exact =  7.9175274853766402778;
points = floor(logspace(0,7,100));

figure;
load('oppervlakte.mat');
rel = abs(oppervlakte-exact)./exact;
Y = [mean(rel'); min(rel'); max(rel')];
h = area(points,Y'); % Set BaseValue via argument
set(h(1),'FaceColor',[1 1 1])
set(h(2),'FaceColor',[0 0.8 0])
set(h(3),'FaceColor',[0 0.6 0])
set(gca,'XScale','log','YScale','log');
axis tight

%% Timetest



R = rand(10^5,2);
R(:,1)=R(:,1)*5-2.5;
R(:,2)=R(:,2)*4-0.5;
tic
inside = is_inside(R(:,1),R(:,2));
time(1) = toc;

R = rand(10^6,2);
R(:,1)=R(:,1)*5-2.5;
R(:,2)=R(:,2)*4-0.5;
tic
inside = is_inside(R(:,1),R(:,2));
time(2) = toc;

R = rand(10^7,2);
R(:,1)=R(:,1)*5-2.5;
R(:,2)=R(:,2)*4-0.5;
tic
inside = is_inside(R(:,1),R(:,2));
time(3) = toc;

R = rand(10^8,2);
R(:,1)=R(:,1)*5-2.5;
R(:,2)=R(:,2)*4-0.5;
tic
inside = is_inside(R(:,1),R(:,2));
time(4) = toc;


time

